﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace CSharpDesign.BLL
{
    public class OrderMangerService
    {
        public static string Select_Value(int iCount, string selectedValue, ref string strTop)
        {
            if (iCount > 1)
            {
                strTop = "top " + iCount.ToString();
            }

            string sql = "select  " + strTop + "  * from [GouWuChe] where  OrderStite='" + selectedValue + "' ";
            return sql;
        }
        /// <summary>
        /// 鼠标移动变色
        /// </summary>
        /// <param name="e"></param>
        public static void Color(GridViewRowEventArgs e)
        {
            //鼠标移动变色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f6f6f6',this.style.fontWeight='';");
                //当鼠标离开的时候 将背景颜色还原的以前的颜色 
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }
            //单击行改变行背景颜色 
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#f6f6f6'; this.style.color='buttontext';this.style.cursor='default';");
            }
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="mydata"></param>
        /// <param name="ID"></param>
        public static void Delete_Orderid(string ID)
        {
            SqlHelper mydata = new SqlHelper();
            mydata.RunSql("delete  from DingDan  where  OrderID='" + ID + "'");
            mydata.RunSql("delete  from GouWuChe  where  Orderid='" + ID + "'");
        }
        public static DataSet sql_con(string sql)
        {
            SqlConnection con = new SqlConnection(SqlHelper.connstring);
            SqlCommand cmd = new SqlCommand(sql, con);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = null;
            try
            {
                con.Open();
                ds = new DataSet();
                da.Fill(ds);

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return ds;
        }
    }
}